package ua.kpi_java_training.tyshchenko.module2;

/**
 * Class's behavior of movement in four directions
 *
 * @author Vlad Tyshchenko
 * @version 13 June 2013
 */
public class MovementInFourDirections extends MovementBehavior {
    final int AMOUNT_DIRECTION = 4;

    public MovementInFourDirections(Position position) {
        super(position);
    }

    /**
     * Method get random number [0, 3] and chooses directions of movement of fish
     * If number is 0 - left;
     * If number is 1 - up;
     * If number is 2 - right;
     * If number is 3 - down;
     *
     * @param lengthStep the amount of steps per cycle
     */
    void move(int lengthStep) {
        AbstractRand rand = new RandomNumber();
        boolean checkMove = false;
        do {
            int direction = rand.getDirection(AMOUNT_DIRECTION);
            if (direction == 0) {
                checkMove = position.robCoordinateX(lengthStep);
            } else if (direction == 1) {
                checkMove = position.robCoordinateY(lengthStep);
            } else if (direction == 2) {
                checkMove = position.addCoordinateX(lengthStep);
            } else if (direction == 3) {
                checkMove = position.addCoordinateY(lengthStep);
            }
        } while (!checkMove);
    }

    /**
     * Mock object
     */
    public void move(AbstractRand rand, int lengthStep) {
        boolean checkMove = false;
        do {
            int direction = rand.getDirection(AMOUNT_DIRECTION);
            if (direction == 0) {
                checkMove = position.robCoordinateX(lengthStep);
            } else if (direction == 1) {
                checkMove = position.robCoordinateY(lengthStep);
            } else if (direction == 2) {
                checkMove = position.addCoordinateX(lengthStep);
            } else if (direction == 3) {
                checkMove = position.addCoordinateY(lengthStep);
            }
        } while (!checkMove);
    }
}
